#ifndef FS_DIR_H
#define FS_DIR_H

#include "fs.h"
#include "stdint.h"
#include "global.h"

#define MAX_FILE_NAME_LEN 16
/* 目录结构 */
struct dir {
    struct inode* inode; // 该目录的inode
    uint32_t dir_pos; // 目录项偏移量
    uint8_t dir_buf[512]; // 读取目录时, 缓存返回的目录项
};

/* 目录项结构 */
struct dir_entry {
    char filename[MAX_FILE_NAME_LEN];
    uint32_t i_no;
    enum file_type f_type;
};

//extern struct dir root_dir;

/* 函数声明 */
void open_root_dir(struct partition* part);
struct dir* dir_open(struct partition* part, uint32_t inode_no);
bool search_dir_entry(struct partition* part, struct dir* pdir, const char* name, struct dir_entry* dir_e);
void dir_close(struct dir* dir);
void create_dir_entry(char* filename, uint32_t inode_no, enum file_type ftype, struct dir_entry* p_de);
bool sync_dir_entry(struct dir* parent_dir, struct dir_entry* p_de, void* io_buf);
bool delete_dir_entry(struct partition *part, struct dir *pdir, uint32_t inode_no, void *io_buf);
struct dir_entry *dir_read(struct dir *dir);
bool dir_is_empty(struct dir *dir);
int32_t dir_remove(struct dir *parent_dir, struct dir *child_dir);
#endif // FS_DIR_H